//
//  UIButton+Extension.swift
//  WeiBo
//
//  Created by 姜伦 on 17/1/13.
//  Copyright © 2017年 DjangoGG. All rights reserved.
//

import UIKit

extension UIButton {
    
    
    /// 便利构造函数
    ///
    /// - parameter image:     图片名
    /// - parameter backImage: 背景图片名
    ///
    /// - returns: UIButton
    convenience init(withImage image: String, backImage: String?) {
        self.init()
        
        setImage(UIImage(named: image), for: .normal)
        setImage(UIImage(named: image + "_highlighted"), for: .highlighted)
        
        if let backImage = backImage {
            setBackgroundImage(UIImage(named: backImage), for: .normal)
            setBackgroundImage(UIImage(named: backImage + "_highlighted"), for: .highlighted)
        }
        
        sizeToFit()
    }
    
    /// 便利构造函数
    ///
    /// - parameter title:         title
    /// - parameter fontSize:      fontSize
    /// - parameter color:         color
    /// - parameter backImageName: backImageName
    ///
    /// - returns: UIButton
    convenience init(withTitle title: String, fontSize: CGFloat, color: UIColor, backImageName: String?) {
        
        self.init()
        
        setTitle(title, for: .normal)
        titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        setTitleColor(color, for: .normal)
        
        if let backImgName = backImageName {
            setBackgroundImage(UIImage(named: backImgName), for: .normal)
        }
    }
    
}
